
(function() {

    var _curCount = 0;

    function tryMaskTweet($tweet) {

        var blackList = blockerConfig.blockedUsers;

        var $user = $tweet.find('a.ti-uname');

        if (blackList.indexOf($user.attr("title").toLowerCase()) >= 0) {

            $tweet.find(".inner-content").html(
                blockerConfig.blockedTips
            );

            if (blockerConfig.blockedTweetImages) {

                $tweet.find(".tiimg-wrapper").html(
                    "<strong>***Images were blocked.***</strong>"
                );
            }
        }
    }

    function handleHotTweets() {

        var $hotTweets = $("article.hot-tweet>div.tweetitem");

        $hotTweets.each(function() {

            tryMaskTweet($(this));
        });
    }

    function onNewLoaded() {

        var $tweetList = $("#v-tweetlist>.tweetitem");

        if (_curCount == $tweetList.length) {
            return;
        }

        console.log('Blocker4OxC: Tweets list loaded a new segment.');

        _curCount = $tweetList.length;

        $tweetList.each(function() {

            tryMaskTweet($(this));
        });
    }

    prLoaded.then(function() {

        $(window).on('scroll', onNewLoaded).trigger('scroll');
        handleHotTweets();
    });
})();
